package com.py.credit.controller;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.ColumnAndCal;
import com.py.credit.entity.DictDetailEntity;
import com.py.credit.entity.Index;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.IndexTableEnum;
import com.py.credit.service.CardsService;
import com.py.credit.service.IndexService;
import com.py.credit.service.SysDictService;
import com.py.credit.service.XypjRemoteBaseService;
import com.py.credit.utils.ExcelUtil;
import com.py.credit.utils.FileUtil;
import com.py.credit.utils.MapCache;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    private final static String FRONT_TABLE_ID = "index";
    @Autowired
    private IndexService indexService;
    @Autowired
    private XypjRemoteBaseService xypjRemoteBaseService;
    @Autowired
    SysDictService sysDictService;
    @Autowired
    CardsService cardsService;

    // 区域常量
    private static final String ZONE = "ZONE";

    /**
     * 获取初始化列
     *
     * @return
     */
    @RequestMapping(value = "/getOptionalColums.json")
    public RestServiceResult<List<OptionalColumn>> getOptionalColums() {
        RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
        try {
            r = new RestServiceResult<List<OptionalColumn>>(IndexTableEnum.getOptionalColumns());
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("系统异常");
        }
        return r;
    }

    /**
     * Description:通过key值获取字典的value
     *
     * @param dictKey
     * @return
     * @author tengt 时间： 2018年12月26日 下午2:14:58
     */
    @RequestMapping(value = "/getIndexDictory.json")
    public RestServiceResult<List<DictDetailEntity>> getIndexDictory(String dictKey) {
        RestServiceResult<List<DictDetailEntity>> r = new RestServiceResult<List<DictDetailEntity>>();
        try {
            List<DictDetailEntity> map = sysDictService.getDictDetails(dictKey, StringUtils.EMPTY);
            r.setData(map);
            return r;
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("字典值查询失败！");
            return r;
        }
    }

    /**
     * @api {get} /shareLog/getTableList.json 获取表规则列表
     * @apiName getTableList
     * @apiVersion 0.0.1
     * @apiGroup 表规则管理
     * @apiParam {String} condition 查询条件(可选)
     * @apiParam {int} limit 每页展示条数 (必需)
     * @apiParam {int} page 当前页数 (必需)
     * @apiSuccess {String} code 状态码:1 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {Object[]} data 结果集
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
     */
    @RequestMapping(value = "/getIndexTableList.json")
    public RestServiceResult<List<LinkedHashMap<String, Object>>> getTableList(
            @RequestParam(value = "type", defaultValue = "") String type,
            @RequestParam(value = "mainType", defaultValue = "") String mainType,
            @RequestParam(value = "name", defaultValue = "") String name,
            @RequestParam(value = "status", defaultValue = "") String status,
            @RequestParam(value = "condition", defaultValue = "") String condition, Page page,
            HttpServletRequest request) {

        String token = HttpServletHelper.getUserToken(request);
        RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
        // 获取当前用户信息
        RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(token);
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
                return result;
            }
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;
        }

        String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
        List<String> showColumns = (configColumns == null || configColumns.length == 0)
                ? IndexTableEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
        // condition="[{columnEN:\"batch_id\",value:\"EX-test-1-20180326-1174\",type:\"varchar\",fuzzy:fasle}]";
        RestServiceResult<List<LinkedHashMap<String, Object>>> r = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
        try {
            List<LinkedHashMap<String, Object>> tableList = indexService.getByConditionForPage(type, mainType, name,
                    status, showColumns, new String[]{"id", "modelName"}, condition, page);
            r = new RestServiceResult<List<LinkedHashMap<String, Object>>>(page.getTotalCount(), tableList);
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("系统异常！");
        }
        return r;
    }

    @RequestMapping(value = "/export.json")
    public RestServiceResult<List<LinkedHashMap<String, Object>>> exportData(
            @RequestParam(value = "type", defaultValue = "") String type,
            @RequestParam(value = "mainType", defaultValue = "") String mainType,
            @RequestParam(value = "name", defaultValue = "") String name,
            @RequestParam(value = "status", defaultValue = "") String status,
            @RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
            @RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
            HttpServletResponse response, HttpServletRequest request) {
        page.setLimit(1000);
        List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
        List<OptionalColumn> optionalColumns = IndexTableEnum.getOptionalColumns();
        List<LinkedHashMap<String, Object>> data;
        RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
        RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("AchievementController#getAchievementCount", "未获取到当前用户信息！");
                return result;
            }
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;
        }
        try {
            data = indexService.getByConditionForPage(type, mainType, name, status, showColumns, null, condition, page);
            if (RestServiceResult.CODE_SUCCESS != result.getCode()) {
                return result;
            }
            ExcelUtil.downloadLinkExcel(response, data, "报告领取列表", "报告领取列表", showColumns, optionalColumns);
            return result;
        } catch (Exception e) {
            result.setCode(RestServiceResult.CODE_UNKNOW);
            result.setMsg("报告领取导出异常，请稍后再试！");
            ExceptionLogger.error("报告领取导出异常！", e.getMessage(), e);
            return result;
        }
    }

    @RequestMapping(value = "/getAdvancedConditionColumns.json")
    public RestServiceResult<List<OptionalColumn>> getAdvancedConditionColumns() {
        RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
        try {
            r = new RestServiceResult<List<OptionalColumn>>(IndexTableEnum.getAdvancedConditionColumns());
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("系统异常");
        }
        return r;

    }

    /**
     * 手动选择展示列
     *
     * @param columns
     * @return
     */
    @RequestMapping(value = "/addShowColunms.json")
    public RestServiceResult<String> addShowColunms(@RequestParam(value = "columns", required = true) String[] columns,
                                                    HttpServletRequest request) {
        RestServiceResult<String> result = new RestServiceResult<String>();
        // 获取当前用户信息
        RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("AchievementController#addShowColunms", "未获取到当前用户信息！");
                return result;
            }
            String column = StringUtils.join(columns, ",");
            MapCache.set(userInfo.getId() + "_" + FRONT_TABLE_ID, StringUtils.split(column, ","));
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;
        }
        return new RestServiceResult<String>();
    }

    /**
     * @api {post} /index/saveOrUpdate.do 编辑或新增指标
     * @apiName saveOrUpdate
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {Index} entity 指标实体
     * @apiParam {String} id 指标id,
     * @apiParam {String} name 指标名称,
     * @apiParam {String} type 指标类型,
     * @apiParam {String} inputType 输入类型,
     * @apiParam {String} checkExp 正则表达式,
     * @apiParam {String} des 指标描述,
     * @apiParam {String} dictSource 字典来源,
     * @apiParam {String} callType 调用类型,
     * @apiParam {String} callContent 调用内容,
     * @apiParam {String} isRequried 是否必填,
     * @apiParam {String} isEditable 是否可编辑,
     * @apiParam {String} isVisible 是否可见,
     * @apiParam {String} isUpload 是否上传,
     * @apiParam {String} xgr 修改人,
     * @apiParam {String} cjr 创建人,
     * @apiParam {String} tip 指标提示,
     * @apiParam {String} relateSource 关联表,
     * @apiParam {String} mainType 库名
     * @apiParamExample {json} 请求参数示例 {"name":"企业资金","type":"定量指标"..}
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/saveOrUpdate.do")
    public RestServiceResult<Object> saveOrUpdate(@RequestBody Index entity) {
        RestServiceResult<Object> r = new RestServiceResult<>();
        if (StringUtils.isNotEmpty(entity.getCallContent())) {
            RestServiceResult result = xypjRemoteBaseService.getValueBySql(entity.getCallContent(), null);
            if (result.getCode() == RestServiceResult.CODE_UNKNOW) {
                r.setCode(RestServiceResult.CODE_UNKNOW);
                r.setMsg("sql语法不合法,请重新检查sql");
                return r;
            }
        }
        if (entity.getId() != null) {
            try {
                indexService.updateIndexById(entity);
            } catch (Exception e) {
                r.setCode(RestServiceResult.CODE_UNKNOW);
                r.setMsg("指标编辑失败！");
            }
        } else {
            try {
                indexService.insertIndex(entity);
            } catch (Exception e) {
                r.setCode(RestServiceResult.CODE_UNKNOW);
                r.setMsg("指标添加失败！" + e.getMessage());
            }
        }
        return r;
    }

    /**
     * @api {post} /index/del.do 编辑或新增指标
     * @apiName del
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {List} ids 指标id
     * @apiParamExample {json} 请求参数示例
     * ["91f2ff1d22194387bc697e194e5193cd","f07abef3cf0b4823a028c8506194f12a"]
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/del.do")
    public RestServiceResult<Object> del(@RequestParam(value = "ids", defaultValue = "") List<String> ids) {
        RestServiceResult<Object> r = new RestServiceResult<Object>();
        try {
            indexService.deleteIndexById(ids);
            indexService.deleteIndexAndCatgoryById(ids);
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标删除失败！");
        }
        return r;
    }

    /**
     * @api {post} /index/indexDelCheck.do 指标删除校验重复
     * @apiName indexDelCheck
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {List} ids 指标id
     * @apiParamExample {json} 请求参数示例
     * ["91f2ff1d22194387bc697e194e5193cd","f07abef3cf0b4823a028c8506194f12a"]
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/indexDelCheck.do")
    public RestServiceResult<Object> indexDelCheck(@RequestParam(value = "ids", defaultValue = "") List<String> ids) {
        RestServiceResult<Object> r = new RestServiceResult<Object>();
        try {
            r.setData(indexService.indexDelCheck(ids));
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标删除检验失败！");
        }
        return r;
    }

    /**
     * @api {post} /index/selectOne.json 查询单个指标
     * @apiName selectOne
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {String} id 指标id,
     * @apiParam {String} name 指标名称,
     * @apiParam {String} type 指标类型
     * @apiParamExample {json} 请求参数示例
     * {id:"f07abef3cf0b4823a028c8506194f12a",name:"注册资本",type:"定量指标"}
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/selectOne.json")
    public RestServiceResult<Object> selectOne(@RequestParam(value = "id", defaultValue = "") String id,
                                               @RequestParam(value = "name", defaultValue = "") String name,
                                               @RequestParam(value = "type", defaultValue = "") String type,
                                               @RequestParam(value = "mainType", defaultValue = "") String mainType) {
        RestServiceResult<Object> r = new RestServiceResult<Object>();
        try {
            Index index = indexService.selectIndexById(id, name, type, mainType);
            r.setData(index);
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("单个指标查询失败！或指标验重失败！");
        }
        return r;

    }

    /**
     * @api {post} /index/getTableList.json 列表查询指标信息
     * @apiName getTableList
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {String} mainType 库名,
     * @apiParam {String} name 指标名称,
     * @apiParam {String} type 指标类型
     * @apiParamExample {json} 请求参数示例 {mainType:"法人库",name:"注册资本",type:"定量指标"}
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/getTableList.json")
    public RestServiceResult<List<Index>> getTableList(@RequestParam(value = "type", defaultValue = "") String type,
                                                       @RequestParam(value = "mainType", defaultValue = "") String mainType,
                                                       @RequestParam(value = "name", defaultValue = "") String name, Page page) {
        RestServiceResult<List<Index>> r = new RestServiceResult<List<Index>>();
        try {
            r.setData(indexService.getIndexForPage(type, mainType, name, page));
            r.setCount(page.getTotalCount());
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标查询所有失败！");
        }
        return r;

    }

    /**
     * @api {post} /index/getDict.json 查询所有字典的key和value值
     * @apiName getDict
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {String} dictKey 字典key值
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/getDict.json")
    public RestServiceResult<List<LinkedHashMap>> getDict() {
        RestServiceResult<List<LinkedHashMap>> r = new RestServiceResult<List<LinkedHashMap>>();
        try {
            r.setData(sysDictService.seletctDictInfo());
            return r;
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("字典key,value值查询失败！");
            return r;
        }
    }

    /**
     * @api {post} /index/getRelateSourceById.json 按指标id查询指标绑定的表名
     * @apiName getRelateSourceById
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiParam {List} ids
     * @apiParamExample {json} 请求参数示例
     * ["f07abef3cf0b4823a028c8506194f12a","f07abef3cf0b4823a028c8506194f12a"]
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/getRelateSourceById.json")
    public RestServiceResult<List<Integer>> getRelateSourceById(
            @RequestParam(value = "list", defaultValue = "") List<String> ids) {
        RestServiceResult<List<Integer>> r = new RestServiceResult<List<Integer>>();
        try {
            r.setData(indexService.selectRelateSourceById(ids));
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标绑定表表名查询失败！");

        }
        return r;
    }

    /**
     * @api {post} /index/getTreeFromIndex.json 创建指标树
     * @apiName getTreeFromIndex
     * @apiVersion 0.0.1
     * @apiGroup 指标管理
     * @apiSuccess {String} code 状态码:0 成功 -1 失败
     * @apiSuccess {String} msg 错误信息
     * @apiSuccess {int} count 结果集数据量
     * @apiSuccess {String} data 结果集
     * @apiSuccess {String} result
     * @apiSuccessExample {json} 成功返回结果
     * {"code":0,"msg":null,"count":0,"data":null}
     */
    @RequestMapping(value = "/getTreeFromIndex.json")
    public RestServiceResult<List<LinkedHashMap>> getTreeFromIndex(
            @RequestParam(value = "mainType", defaultValue = "") String mainType,
            @RequestParam(value = "name", defaultValue = "") String name) {
        RestServiceResult<List<LinkedHashMap>> r = new RestServiceResult<List<LinkedHashMap>>();
        try {
            r.setData(indexService.selectTreeFromIndex(mainType, name));
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标树查询失败！");

        }
        return r;
    }

    @RequestMapping(value = "/getCalFormulaBycolName", method = RequestMethod.GET)
    @ApiOperation(value = "获取财务利率信息(在后台指标添加或修改，选用财务指标时调用)", httpMethod = "GET", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "colNameEN", value = "利率字段名(英文)", required = false)})
    public RestServiceResult<List<ColumnAndCal>> getcalFormulaBycolName(
            @RequestParam(value = "colNameEN", required = false) String colNameEN) {

        RestServiceResult<List<ColumnAndCal>> r = new RestServiceResult<>();
        try {
            r.setData(indexService.selectCalFormulaBycolName(colNameEN));
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("财务树查询失败！");

        }
        return r;

    }

    @RequestMapping(value = "/saveFinanceData.do", method = RequestMethod.GET)
    @ApiOperation(value = "保存指定公司利率信息(在用户上传基础财务表时调用)", httpMethod = "GET", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "pgId", value = "pgid", required = false)})
    public RestServiceResult<Object> saveFinanceData(@RequestParam(value = "pgId", required = false) String pgId) {
        RestServiceResult<Object> r = new RestServiceResult<Object>();
        try {
            indexService.saveFinanceData(pgId);
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            System.out.println(e.getMessage());
            e.printStackTrace();
            r.setMsg("指标添加失败！");
        }
        return r;
    }

    // @RequestMapping(value = "/getExistCards")
    // @ApiOperation(value = "获取是否存在该类证照(在前台调写证照类指标时调用)", httpMethod = "GET",
    // produces = "application/json")
    // public RestServiceResult<Cards> getExistCards(@RequestParam(value =
    // "cardType", required = false) String cardType,
    // @RequestParam(value = "userId", required = false) String userId) {
    // RestServiceResult<Cards> r = new RestServiceResult<Cards>();
    // try {
    // r.setData(cardsService.selectCardsDetail(null, "1",cardType,userId,"2"));
    // } catch (Exception e) {
    // r.setCode(RestServiceResult.CODE_UNKNOW);
    // r.setMsg("获取是否存在该类证照失败！");
    // }
    // return r;
    // }

    @RequestMapping(value = "/getCalData", method = RequestMethod.GET)
    @ApiOperation(value = "获取企业财务利率数据(前台用户填写财务指标时调用)", httpMethod = "GET", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "colNameEN", value = "利率字段名(英文)", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "pgId", value = "pgId", required = false)})
    public RestServiceResult<ColumnAndCal> getCalData(@RequestParam(value = "pgId", required = false) String pgId,
                                                      @RequestParam(value = "colNameEN", required = false) String colNameEN) {

        return new RestServiceResult<ColumnAndCal>();

    }

    @RequestMapping(value = "/getIndexDataForPage.json")
    @ApiOperation(value = "查询指标相关数据(在后台审核的界面调用)", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "shzt", value = "审核状态", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "relateSource", value = "表来源", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "indexType", value = "指标类型", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "callType", value = "调用类型", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "type", value = "证照类型", required = false)})
    public RestServiceResult<List<LinkedHashMap<String, Object>>> getCardsInfo(
            @RequestParam(value = "userId", defaultValue = "", required = true) String userId,
            @RequestParam(value = "shzt", defaultValue = "", required = false) String shzt,
            @RequestParam(value = "relateSource", defaultValue = "", required = false) String relateSource,
            @RequestParam(value = "indexType", defaultValue = "", required = true) String indexType,
            @RequestParam(value = "callType", defaultValue = "", required = false) String callType,
            @RequestParam(value = "type", defaultValue = "", required = false) String type, Page page) {
        RestServiceResult<List<LinkedHashMap<String, Object>>> r = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
        try {
            if (indexType.equals("6")) {
                r.setData(cardsService.selectCardsForPage(type, userId, shzt, page));
                r.setCount(page.getTotalCount());
            }
            if (callType.equals("2")) {
                r.setData(indexService.searchFinanceIndexData(userId));
                r.setCount(page.getTotalCount());
            }
            if (null != relateSource && !("").equals(relateSource)) {
                String tybm = indexService.getTybmById(userId);
                r = xypjRemoteBaseService.getIndexInfoByTybm(relateSource, tybm, userId);
            }
        } catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("查询指标相关数据失败！");
        }
        return r;
    }

    @RequestMapping(value = "/downReportFile.json")
    public void downReportFile(@RequestParam(value = "fileUrl", required = true) String fileUrl,
                               HttpServletResponse response, HttpServletRequest request) {
        RestServiceResult r = new RestServiceResult();
        RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                r.setCode(RestServiceResult.CODE_UNKNOW);
                r.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("AchievementController#getAchievementCount", "未获取到当前用户信息！");
            }
        } else {
            r.setCode(user.getCode());
            r.setMsg(user.getMsg());

        }
        if (!FileUtil.downloadFile(fileUrl, response)) {
            r.setMsg("下载失败，请稍后再试");
            ExceptionLogger.error("reportGet#downReportFile", "报告资料领取失败");
        }

    }

    @IgnoreAuthority
    @RequestMapping(value = "/getModelBindIndex.json")
    public RestServiceResult<List<Map<String, String>>> getModelBindIndex(
            @RequestParam(value = "id", required = true) String id, Page page) {
        RestServiceResult<List<Map<String, String>>> r = new RestServiceResult<>();
        try {
            r.setData(indexService.selectModelBindIndex(id, page));
            r.setCount(page.getTotalCount());
        } catch (Exception e) {

            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("指标绑定模型查询失败");
        }
        return r;
    }
}
